﻿using System;
using System.Threading;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Net;
using System.IO;

namespace Host
{
	public class TCPServerComponents : IComponents
	{
		private Thread _welcome_thread;
		private Thread _handle_thread;

		private List<Socket> _new_socket_list = new List<Socket>();
		private List<Socket> _socket_list = new List<Socket>();

		public TCPServerComponents()
		{

		}

		private void HandleNewSoket(Socket socket)
		{
			
		}

		/// <summary>
		/// 创建组件时
		/// </summary>
		public override void OnAdd()
		{
			_welcome_thread = new Thread(() =>
			{

			});
			_welcome_thread.IsBackground = true;
			_welcome_thread.Start();

			_handle_thread = new Thread(() => 
			{
				
			});
			_handle_thread.IsBackground = true;
			_handle_thread.Start();
		}

		/// <summary>
		/// 组件进入时
		/// </summary>
		public override void OnEnter()
		{

		}

		/// <summary>
		/// 组件退出时
		/// </summary>
		public override void OnExit()
		{

		}

		/// <summary>
		/// 组件移除时
		/// </summary>
		public override void OnRemove()
		{
			while (_welcome_thread.ThreadState != ThreadState.Stopped
				 && _welcome_thread.ThreadState != ThreadState.Suspended
				 && _welcome_thread.ThreadState != ThreadState.Aborted)
				Thread.Sleep(100);

			while (_handle_thread.ThreadState != ThreadState.Stopped
				 && _handle_thread.ThreadState != ThreadState.Suspended
				 && _handle_thread.ThreadState != ThreadState.Aborted)
				Thread.Sleep(100);
		}
	}
}
